package com.huluobo.a2203kotlinshopping.register

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.blankj.utilcode.util.ToastUtils
import com.huluobo.a2203kotlinshopping.R
import com.huluobo.a2203kotlinshopping.databinding.ActivityRegisterBinding
import com.huluobo.a2203kotlinshopping.databinding.ActivityRoomBinding
import com.huluobo.base.view.BaseMVVMActivity

class RegisterActivity : BaseMVVMActivity<ActivityRegisterBinding, RegisterViewModel>() {
    override fun getViewModel(): Class<RegisterViewModel> = RegisterViewModel::class.java

    override fun initData() {
        viewModel.registerSuccess.observe(this) {
            ToastUtils.showLong(it.message)
            if (it.code == 200) {
                finish()
            }
        }

        viewModel.registerFailed.observe(this) {
            ToastUtils.showLong("注册失败:$it")
        }
    }

    override fun initView() {
        dataBinding.registerBtn.setOnClickListener {
            viewModel.register(
                dataBinding.registerUsernameEt.text.toString(),
                dataBinding.registerPasswordEt.text.toString(),
                dataBinding.registerRePasswordEt.text.toString()
            )
        }
    }

    override fun getLayoutId(): Int = R.layout.activity_register
}